﻿package mortal.common.tools
{

    public class DateParser extends Object
    {
        private static var _date:Date = new Date();
        private static var _parserList:Array = [{fun:yyyy, str:"yyyy"}, {fun:yy, str:"yy"}, {fun:y, str:"y"}, {fun:MM, str:"MM"}, {fun:M, str:"M"}, {fun:dd, str:"dd"}, {fun:d, str:"d"}, {fun:hh, str:"hh"}, {fun:h, str:"h"}, {fun:mm, str:"mm"}, {fun:m, str:"m"}, {fun:ss, str:"ss"}, {fun:s, str:"s"}, {fun:jjj, str:"jjj"}];

        public function DateParser()
        {
            return;
        }// end function

        public static function parse(param1:Date, param2:String) : String
        {
            var _loc_4:Object = null;
            _date = param1;
            var _loc_3:int = 0;
            while (_loc_3 < _parserList.length)
            {
                
                _loc_4 = _parserList[_loc_3];
                param2 = param2.replace(_loc_4.str, (_loc_4.fun as Function).call());
                _loc_3++;
            }
            return param2;
        }// end function

        public static function strToDate(param1:String) : Date
        {
            var _loc_2:* = param1.match(/\d+""\d+/g);
            while (_loc_2.length < 7)
            {
                
                _loc_2.push("0");
            }
            return new Date(Number(_loc_2[0]), Number(_loc_2[1]), Number(_loc_2[2]), Number(_loc_2[3]), Number(_loc_2[4]), Number(_loc_2[5]), Number(_loc_2[6]));
        }// end function

        public static function strToDateNormal(param1:String) : Date
        {
            var _loc_2:* = param1.match(/\d+""\d+/g);
            while (_loc_2.length < 7)
            {
                
                _loc_2.push("0");
            }
            return new Date(Number(_loc_2[0]), (Number(_loc_2[1]) - 1), Number(_loc_2[2]), Number(_loc_2[3]), Number(_loc_2[4]), Number(_loc_2[5]), Number(_loc_2[6]));
        }// end function

        private static function yyyy() : String
        {
            return _date.fullYear.toString();
        }// end function

        private static function yy() : String
        {
            return _date.fullYear.toString().slice(2);
        }// end function

        private static function y() : String
        {
            return _date.fullYear.toString().slice(3);
        }// end function

        private static function MM() : String
        {
            return ((_date.getMonth() + 1) < 10 ? ("0") : ("")) + (_date.getMonth() + 1);
        }// end function

        private static function M() : String
        {
            return ((_date.getMonth() + 1)).toString();
        }// end function

        private static function dd() : String
        {
            return (_date.getDate() < 10 ? ("0") : ("")) + _date.getDate();
        }// end function

        private static function d() : String
        {
            return _date.getDate().toString();
        }// end function

        private static function hh() : String
        {
            return (_date.getHours() < 10 ? ("0") : ("")) + _date.getHours();
        }// end function

        private static function h() : String
        {
            return _date.getHours().toString();
        }// end function

        private static function mm() : String
        {
            return (_date.getMinutes() < 10 ? ("0") : ("")) + _date.getMinutes();
        }// end function

        private static function m() : String
        {
            return _date.getMinutes().toString();
        }// end function

        private static function ss() : String
        {
            return (_date.getSeconds() < 10 ? ("0") : ("")) + _date.getSeconds();
        }// end function

        private static function s() : String
        {
            return _date.getSeconds().toString();
        }// end function

        private static function jjj() : String
        {
            return _date.milliseconds.toString();
        }// end function

    }
}
